package com.gym.openapi.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gym.openapi.common.ResponseResult;
import com.gym.openapi.common.ResultTable;
import com.gym.openapi.dao.RechargeMapper;
import com.gym.openapi.entity.Recharge;
import com.gym.openapi.services.RechargeServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ming
 * 2021/11/26
 * description:充值管理
 */
@Service
public class RechargeServicesImpl implements RechargeServices {
    @Autowired
    private RechargeMapper rechargeMapper;

    @Override
    public ResultTable reTaBle(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Recharge> lre = rechargeMapper.reTable();
        PageInfo<Recharge> pre = new PageInfo(lre);
        return new ResultTable(0,"msg", (int) pre.getTotal(),pre.getList());
    }

    @Override
    public ResponseResult del(Integer[] ids) {
        int i = rechargeMapper.del(ids);
        if (i>0) {
            return ResponseResult.getSuccess("re删除成功");
        }
        return ResponseResult.getFail("re删除失败");
    }

    @Override
    public ResponseResult update(Recharge re1) {
        if (re1!=null) {
            int i = rechargeMapper.updateByPrimaryKeySelective(re1);
            if (i>0) {

                return ResponseResult.getSuccess("修改re成功");
            }
        }
        return ResponseResult.getFail("失败失败");
    }


    @Override
    public ResponseResult add(Recharge re2) {
        if (re2!=null) {
            int i = rechargeMapper.insertSelective(re2);
            if (i>0) {
                return ResponseResult.getSuccess();
            }
        }
        return ResponseResult.getFail("添加失败");
    }
}
